using System.Collections.Generic;
using I2.Loc;
using UnityEngine;

public class SelectableButtonMode : SelectableButton
{
	[SerializeField]
	private GameObject likeBoxSelected;

	[SerializeField]
	private GameObject likeBoxUnselected;

	[SerializeField]
	private GameObject bonusAward;

	[SerializeField]
	private GameModesUI controllerPanel;

	[SerializeField]
	private List<GameObject> isNewGameObject = new List<GameObject>();

	private UILabel _countPlayersLable;

	private UILabel _descriptionLable;

	private GameModeConfig.ModeInfo _modeInfo;

	private LikeModeButton _likeModeButton;

	private int _percent;

	public UILabel CountPlayersLable
	{
		get
		{
			return _countPlayersLable;
		}
		set
		{
			_countPlayersLable = value;
		}
	}

	public UILabel DescriptionLable
	{
		get
		{
			return _descriptionLable;
		}
		set
		{
			_descriptionLable = value;
		}
	}

	public GameModeConfig.ModeInfo ModeInfo
	{
		get
		{
			return _modeInfo;
		}
		set
		{
			_modeInfo = value;
		}
	}

	public LikeModeButton LikeModeButton
	{
		get
		{
			return _likeModeButton;
		}
		set
		{
			_likeModeButton = value;
		}
	}

	public int Percent
	{
		get
		{
			return _percent;
		}
	}

	private void OnEnable()
	{
		if (ModeInfo.GetTexture() != null)
		{
			SetName(ModeInfo.GetTranslateName()[LocalizationManager.CurrentLanguage]);
		}
	}

	public override void Select(bool select)
	{
		if (select && !selected)
		{
			SetBottomPanelInfo();
			RefresfViewLikeBox();
		}
		base.Select(select);
	}

	public override void OnClick()
	{
		if (selected)
		{
			controllerPanel.Play();
		}
		else
		{
			base.OnClick();
		}
	}

	public void Init()
	{
		SetName(ModeInfo.GetTranslateName()[LocalizationManager.CurrentLanguage]);
		SetAnimation();
		SetTexture();
		foreach (GameObject item in isNewGameObject)
		{
			item.SetActive(ModeInfo.isNew);
		}
		RefresfViewLikeBox();
		RefresBonusAwardLabel();
	}

	public void ModifyPercent(int value)
	{
		SetLikePersent(_percent + value);
	}

	public void SetLikePersent(int percent)
	{
		_percent = percent;
		likeBoxSelected.GetComponentInChildren<UILabel>().text = ((percent < 1000) ? percent.ToString() : (Mathf.Floor(percent / 1000) + "k"));
		likeBoxUnselected.GetComponentInChildren<UILabel>().text = ((percent < 1000) ? percent.ToString() : (Mathf.Floor(percent / 1000) + "k"));
	}

	public void RefresfViewLikeBox()
	{
		bool likeStatus = LikeModeManager.instance.GetLikeStatus(ModeInfo.typeGame);
		likeBoxSelected.SetActive(likeStatus);
		likeBoxUnselected.SetActive(!likeStatus);
	}

	private void SetName(string modeName)
	{
		selectedBG.GetComponentInChildren<UILabel>().text = modeName;
		notSelectedBG.GetComponentInChildren<UILabel>().text = modeName;
	}

	private void SetAnimation()
	{
		if (!(ModeInfo.GetAnimation() == null))
		{
			GameObject gameObject = Object.Instantiate(ModeInfo.GetAnimation());
			gameObject.transform.SetParent(selectedBG.transform);
			gameObject.transform.localScale = Vector3.one;
			gameObject.transform.localPosition = Vector3.zero;
		}
	}

	private void SetTexture()
	{
		if (!(ModeInfo.GetTexture() == null))
		{
			GameObject gameObject = Object.Instantiate(ModeInfo.GetTexture());
			gameObject.transform.SetParent(notSelectedBG.transform);
			gameObject.transform.localScale = Vector3.one;
			gameObject.transform.localPosition = Vector3.zero;
		}
	}

	private void SetBottomPanelInfo()
	{
		CountPlayersLable.text = ModeInfo.playerCount;
		DescriptionLable.text = ScriptLocalization.Get("Game_Common/sm_" + ModeInfo.name + "_info");
		LikeModeButton.ButtonMode = this;
		LikeModeButton.RefreshView();
	}

	private void RefresBonusAwardLabel()
	{
		if ((bool)BonusAwardManager.instance)
		{
			bonusAward.SetActive(BonusAwardManager.instance.IsSetBonus(ModeInfo.typeGame));
		}
	}
}
